﻿ USE [EventScavenger]
GO

CREATE TABLE [dbo].[ImportLogs](
	[ForeignLogID] [int] IDENTITY(1,1) NOT NULL,
	[CollectorID] [int] NOT NULL,
	[Server] [nvarchar](255) NOT NULL,
	[Database] [nvarchar](255) NOT NULL,
	[MachineLogID] [int] NOT NULL
	
 CONSTRAINT [PK_ImportLogs] PRIMARY KEY CLUSTERED 
(
	[ForeignLogID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
--In case the previous version of this update script was run creating the table already
ALTER TABLE dbo.ImportLogs ADD
    [Enabled] bit NOT NULL CONSTRAINT DF_ImportLogs_Enabled DEFAULT 1
GO

ALTER TABLE [dbo].[ImportLogs]  WITH CHECK ADD  CONSTRAINT [FK_ImportLogs_Collectors] FOREIGN KEY([CollectorID])
REFERENCES [dbo].[Collectors] ([CollectorID])
GO

ALTER TABLE [dbo].[ImportLogs] CHECK CONSTRAINT [FK_ImportLogs_Collectors]
GO

ALTER TABLE [dbo].[ImportLogs]  WITH CHECK ADD  CONSTRAINT [FK_ImportLogs_MachineLogs] FOREIGN KEY([MachineLogID])
REFERENCES [dbo].[MachineLogs] ([MachineLogID])
GO

ALTER TABLE [dbo].[ImportLogs] CHECK CONSTRAINT [FK_ImportLogs_MachineLogs]
GO

ALTER TABLE dbo.Collectors ADD
	ImportsEnabled bit NOT NULL CONSTRAINT DF_Collectors_ImportsEnabled DEFAULT 0,
	ImportFrequencyMinutes int NOT NULL CONSTRAINT DF_Collectors_ImportFrequencyMinutes DEFAULT 15
GO

Update Settings SET SettingValue = '3.2' WHERE SettingName like 'DatabaseVersion'
GO